//
//  VRSafetyTestingCell.m
//  VRFirefighting
//
//  Created by Veer on 2018/8/22.
//  Copyright © 2018年 Veer. All rights reserved.
//

#import "VRRiskReportCell.h"

#import "PYPhotoBrowseView.h"
#import "PYPhotosView.h"

#import "VRRiskReportModel.h"

@interface VRRiskReportCell()

@property (nonatomic, assign) UIView *bottomLineView;
@property (nonatomic, weak) UILabel *title0Lbl;
@property (nonatomic, weak) UILabel *title1Lbl;
@property (nonatomic, weak) UILabel *title2Lbl;

@property (nonatomic, strong) UIView *statusBarView;
@property (nonatomic, weak) UILabel *statusLbl;
@property (nonatomic, strong) UIImageView *accessoryImgView;
@property (nonatomic, strong) PYPhotosView *linePhotosView;


@end

@implementation VRRiskReportCell

+ (instancetype)cellWith:(UITableView *)tablevie
{
    static NSString *cellID = @"VRRiskReportCell";
    
    VRRiskReportCell *cell = [tablevie dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        
        cell = [[VRRiskReportCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryNone;
        // lieview
        [self setupSubView];
        
    }
    return self;
}


- (void)setupSubView
{
    
    UIView *selectedBgView = [[UIView alloc] init];
    selectedBgView.backgroundColor = RGB(238, 238, 238);
    self.selectedBackgroundView = selectedBgView;
    
    UILabel *title0Lbl = [[UILabel alloc] init];
    title0Lbl.text = @"巡更目标：";
    title0Lbl.textColor = RGB(51, 51, 51);
    title0Lbl.font = VRFont(14);
    [self.contentView addSubview:title0Lbl];
    self.title0Lbl = title0Lbl;
    
    UILabel *title1Lbl = [[UILabel alloc] init];
    title1Lbl.text = @"巡更低点：";
    title1Lbl.textColor = RGB(51, 51, 51);
    title1Lbl.font = VRFont(14);
    [self.contentView addSubview:title1Lbl];
    self.title1Lbl = title1Lbl;
    
    UILabel *title2Lbl = [[UILabel alloc] init];
    title2Lbl.text = @"巡更组：";
    title2Lbl.textColor = RGB(51, 51, 51);
    title2Lbl.font = VRFont(14);
    [self.contentView addSubview:title2Lbl];
    self.title2Lbl = title2Lbl;
    
    UIView *bottomLineView = [[UIView alloc] init];
    bottomLineView.hidden = YES;
    bottomLineView.backgroundColor = RGB(228, 228, 228);
    [self.contentView addSubview:bottomLineView];
    self.bottomLineView = bottomLineView;
    
    UIView *statusBarView = [[UIView alloc] init];
    statusBarView.backgroundColor = RGB(238, 238, 238);
    [self.contentView addSubview:statusBarView];
    self.statusBarView = statusBarView;
    
    UILabel *signalLbl = [[UILabel alloc] init];
    signalLbl.textColor = RGB(255, 255, 255);
    signalLbl.font = VRFont(14);
    [self.statusBarView addSubview:signalLbl];
    self.statusLbl = signalLbl;
    
    UIImageView *accessoryImgView = [[UIImageView alloc] init];
    accessoryImgView.hidden = YES;
    accessoryImgView.image = [UIImage imageNamed:@"safety_right"];
    accessoryImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.statusBarView addSubview:accessoryImgView];
    self.accessoryImgView = accessoryImgView;
    
    
    // 图片浏览器
    // 1. 创建图片链接数组
    NSMutableArray *thumbnailImageUrls = [NSMutableArray array];
    // 添加图片(缩略图)链接
//    [thumbnailImageUrls addObject:@"http://ww3.sinaimg.cn/thumbnail/006ka0Iygw1f6bqm7zukpj30g60kzdi2.jpg"];
//    [thumbnailImageUrls addObject:@"http://ww1.sinaimg.cn/thumbnail/61b69811gw1f6bqb1bfd2j20b4095dfy.jpg"];
//    [thumbnailImageUrls addObject:@"http://ww1.sinaimg.cn/thumbnail/54477ddfgw1f6bqkbanqoj20ku0rsn4d.jpg"];
//    [thumbnailImageUrls addObject:@"http://ww4.sinaimg.cn/thumbnail/006ka0Iygw1f6b8gpwr2tj30bc0bqmyz.jpg"];
//    [thumbnailImageUrls addObject:@"http://ww2.sinaimg.cn/thumbnail/9c2b5f31jw1f6bqtinmpyj20dw0ae76e.jpg"];
//    [thumbnailImageUrls addObject:@"http://ww1.sinaimg.cn/thumbnail/536e7093jw1f6bqdj3lpjj20va134ana.jpg"];
//    [thumbnailImageUrls addObject:@"http://ww1.sinaimg.cn/thumbnail/75b1a75fjw1f6bqn35ij6j20ck0g8jtf.jpg"];
//    [thumbnailImageUrls addObject:@"http://ww4.sinaimg.cn/bmiddle/406ef017jw1ec40av2nscj20ip4p0b29.jpg"];
//    [thumbnailImageUrls addObject:@"http://ww1.sinaimg.cn/thumbnail/86afb21egw1f6bq3lq0itj20gg0c2myt.jpg"];
    
    // 1.2 创建图片原图链接数组
    NSMutableArray *originalImageUrls = [NSMutableArray array];
    // 添加图片(原图)链接
//    [originalImageUrls addObject:@"http://ww3.sinaimg.cn/large/006ka0Iygw1f6bqm7zukpj30g60kzdi2.jpg"];
//    [originalImageUrls addObject:@"http://ww1.sinaimg.cn/large/61b69811gw1f6bqb1bfd2j20b4095dfy.jpg"];
//    [originalImageUrls addObject:@"http://ww1.sinaimg.cn/large/54477ddfgw1f6bqkbanqoj20ku0rsn4d.jpg"];
//    [originalImageUrls addObject:@"http://ww4.sinaimg.cn/large/006ka0Iygw1f6b8gpwr2tj30bc0bqmyz.jpg"];
//    [originalImageUrls addObject:@"http://ww2.sinaimg.cn/large/9c2b5f31jw1f6bqtinmpyj20dw0ae76e.jpg"];
//    [originalImageUrls addObject:@"http://ww1.sinaimg.cn/large/536e7093jw1f6bqdj3lpjj20va134ana.jpg"];
//    [originalImageUrls addObject:@"http://ww1.sinaimg.cn/large/75b1a75fjw1f6bqn35ij6j20ck0g8jtf.jpg"];
//    [originalImageUrls addObject:@"http://ww4.sinaimg.cn/bmiddle/406ef017jw1ec40av2nscj20ip4p0b29.jpg"];
//    [originalImageUrls addObject:@"http://ww1.sinaimg.cn/large/86afb21egw1f6bq3lq0itj20gg0c2myt.jpg"];
    
    UIView *imgContainView = [[UIView alloc] init];
    imgContainView.frame = CGRectMake(-20, 80 + PYMargin * 2, kScreenWidth + 20, 80);
    [self.contentView addSubview:imgContainView];
    
    // 2.2创建线性布局
//    PYPhotosView *linePhotosView = [PYPhotosView photosViewWithThumbnailUrls:thumbnailImageUrls originalUrls:originalImageUrls layoutType:PYPhotosViewLayoutTypeLine];
    
    PYPhotosView *linePhotosView = [PYPhotosView photosView];
    // 设置Frame
    linePhotosView.py_y = 0;
    linePhotosView.py_x = 40;
//    linePhotosView.py_width = kScreenWidth - 20 * 2;
    
//    linePhotosView.autoLayoutWithWeChatSytle = NO;
    linePhotosView.photosMaxCol = 20;
//    [linePhotosView setLayoutType:PYPhotosViewLayoutTypeLine];
    
    // 3. 添加到指定视图中
    [imgContainView addSubview:linePhotosView];
    self.linePhotosView = linePhotosView;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.title0Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
    
    [self.title1Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(self.contentView.mas_top).offset(50);
        make.right.mas_equalTo(-20);
    }];
    
    [self.title2Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.bottom.mas_equalTo(self.contentView.mas_top).offset(100 - 15);
    }];
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.statusBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(40);
    }];
    
    [self.statusLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(self.statusBarView);
    }];
    
    [self.accessoryImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(self.statusBarView);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(40);
    }];
}


#pragma mark - setter && getter
//- (void)setFrame:(CGRect)frame
//{
//    CGRect rect = frame;
//    rect.size.height = frame.size.height - 10;
//    [super setFrame:rect];
//}

- (void)setModel:(VRRiskReportModel *)model
{
    _model = model;
    
    self.title0Lbl.text = model.fTime;
    self.title1Lbl.text = [NSString stringWithFormat:@"隐患地址：%@", model.fPosition ? model.fPosition : @""];;
    self.title2Lbl.text = [NSString stringWithFormat:@"隐患描述：%@", model.fContent ? model.fContent : @""];
//
    if (model.fState == 2) {
        self.statusLbl.text = [NSString stringWithFormat:@"状态：异常"];
        self.statusBarView.backgroundColor = RGB(225, 11, 24);
    }else{
        self.statusLbl.text = [NSString stringWithFormat:@"状态：正常"];
        self.statusBarView.backgroundColor = RGB(78, 172, 57);
    }
    
    NSArray *imgArray = [model.fPicture componentsSeparatedByString:@","];
    
//    self.linePhotosView.images = [NSMutableArray arrayWithArray:imgArray];
//    [self.linePhotosView setLayoutType:PYPhotosViewLayoutTypeLine];
    [self.linePhotosView setThumbnailUrls:[NSMutableArray arrayWithArray:imgArray]];
    [self.linePhotosView setOriginalUrls:[NSMutableArray arrayWithArray:imgArray]];
//    [self.linePhotosView reloadDataWithImages:[NSMutableArray arrayWithArray:imgArray]];
//    [self.linePhotosView refreshContentSizeWithPhotoCount:imgArray.count];
}

@end
